package cn.etynit.org.controller;
import cn.etynit.basic.anno.LogAnno;
import cn.etynit.basic.anno.PreAuthorize;
import cn.etynit.basic.util.AjaxResult;
import cn.etynit.basic.util.PageList;
import cn.etynit.org.domain.SDdetail;
import cn.etynit.org.query.SDdetailQuery;
import cn.etynit.org.service.SDdetailService;
import io.swagger.annotations.Api;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/sdd")
@Api(value = "数据字典明细的API", description = "数据字典明细相关的CRUD功能")
@LogAnno
public class SDdetailController {

    @Autowired
    private SDdetailService sDdetailService;

    // 查询全部
    public List<SDdetail> findAll(){
        return sDdetailService.findAll();
    }

    // 分页查询
    @PostMapping
    @LogAnno(method = "queryByPage", methodDes = "查询数据字典类型明细")
    public PageList<SDdetail> queryByPage(@RequestBody SDdetailQuery sDdetailQuery){
        return sDdetailService.queryByPage(sDdetailQuery);
    }

    // 新增和修改
    @PutMapping
    @LogAnno(method = "addOrupdate", methodDes = "添加或者修改数据字典类型明细")
    public AjaxResult add(@RequestBody SDdetail sDdetail){
        if (null == sDdetail.getId()){
            //新增
            sDdetailService.add(sDdetail);
        } else {
            // 修改
            sDdetailService.update(sDdetail);
        }
        return AjaxResult.me().success();
    }

    // 根据id删除
    @DeleteMapping("/{id}")
    @LogAnno(method = "delete", methodDes = "删除数据字典类型明细")
    public AjaxResult delete(@PathVariable("id")Long id){
        sDdetailService.delete(id);
        return AjaxResult.me().success();
    }

    // 批量删除
    @PatchMapping
    @LogAnno(method = "batchDel", methodDes = "批量删除数据字典类型明细")
    public AjaxResult batchDel(@RequestBody List<Long> ids){
        sDdetailService.batchDel(ids);
        return AjaxResult.me().success();
    }
}
